package com.xyj.zjbz.util;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import java.util.logging.Logger;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;

public class DynamicDataSource extends AbstractRoutingDataSource {
	public static final Logger logger = Logger
			.getLogger(DynamicDataSource.class.toString());
	
	/**
	 * 覆写此方法，告诉spring应该注入哪个数据源
	 */
	@Override
	protected Object determineCurrentLookupKey() {
		return DataSourceSwitcher.getDataSourceName();
	}

	@Override
	public void setTargetDataSources(Map<Object, Object> targetDataSources) {
		// TODO Auto-generated method stub
		super.setTargetDataSources(targetDataSources);
		super.afterPropertiesSet();
	}

	@Override
	public void setDefaultTargetDataSource(Object defaultTargetDataSource) {
		// TODO Auto-generated method stub
		super.setDefaultTargetDataSource(defaultTargetDataSource);
	}

	@Override
	public void setLenientFallback(boolean lenientFallback) {
		// TODO Auto-generated method stub
		super.setLenientFallback(lenientFallback);
	}

	@Override
	public void setDataSourceLookup(DataSourceLookup dataSourceLookup) {
		// TODO Auto-generated method stub
		super.setDataSourceLookup(dataSourceLookup);
	}

	@Override
	public void afterPropertiesSet() {
		// TODO Auto-generated method stub
		super.afterPropertiesSet();
	}

	@Override
	protected Object resolveSpecifiedLookupKey(Object lookupKey) {
		// TODO Auto-generated method stub
		return super.resolveSpecifiedLookupKey(lookupKey);
	}

	@Override
	protected DataSource resolveSpecifiedDataSource(Object dataSource)
			throws IllegalArgumentException {
		// TODO Auto-generated method stub
		return super.resolveSpecifiedDataSource(dataSource);
	}

	@Override
	public Connection getConnection() throws SQLException {
		// TODO Auto-generated method stub
		return super.getConnection();
	}

	@Override
	public Connection getConnection(String username, String password)
			throws SQLException {
		// TODO Auto-generated method stub
		return super.getConnection(username, password);
	}

	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException {
		// TODO Auto-generated method stub
		return super.unwrap(iface);
	}

	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		// TODO Auto-generated method stub
		return super.isWrapperFor(iface);
	}

	@Override
	protected DataSource determineTargetDataSource() {
		// TODO Auto-generated method stub
		return super.determineTargetDataSource();
	}

	@Override
	public int getLoginTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return super.getLoginTimeout();
	}

	@Override
	public void setLoginTimeout(int timeout) throws SQLException {
		// TODO Auto-generated method stub
		super.setLoginTimeout(timeout);
	}

	@Override
	public PrintWriter getLogWriter() {
		// TODO Auto-generated method stub
		return super.getLogWriter();
	}

	@Override
	public void setLogWriter(PrintWriter pw) throws SQLException {
		// TODO Auto-generated method stub
		super.setLogWriter(pw);
	}

	@Override
	public Logger getParentLogger() {
		// TODO Auto-generated method stub
		return super.getParentLogger();
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return super.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		return super.equals(obj);
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}

	@Override
	protected void finalize() throws Throwable {
		// TODO Auto-generated method stub
		super.finalize();
	}

	@Override
	public void addDataSource(Object key, Object dataSource) {
		// TODO Auto-generated method stub
		super.addDataSource(key, dataSource);
	}

	
}
